//
//  UIButton+MyButton.m
//  你来猜
//
//  Created by zero on 16/12/18.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "UIButton+ZButton.h"

@implementation UIButton (ZButton)

#pragma mark
#pragma mark - 主方法
- (instancetype)initWithNormalImageName:(NSString *)normalImageName
                andHighLightedImageName:(NSString *)highLightedName
                   andSelectedImageName:(NSString *)selectedName
                               andImage:(NSString *)imageName
                   andImageSelectedName:(NSString *)imageSelected
                               andTitle:(NSString *)title
                               andFrame:(CGRect)frame{
    
    if (self = [super init]) {
        
        //  实例化一个按钮
        UIButton *btn = [[UIButton alloc]init];
        //  设置按钮的title
        [btn setTitle:title forState:UIControlStateNormal];
        //  设置按钮的颜色
        [btn setTintColor:[UIColor whiteColor]];
        //  设置图片的image属性
        [btn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:imageSelected] forState:UIControlStateHighlighted];
        //  设置背景图片
        [btn setBackgroundImage:[UIImage imageNamed:normalImageName] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:highLightedName] forState:UIControlStateHighlighted];
        //  设置按钮的选中图片
        [btn setBackgroundImage:[UIImage imageNamed:selectedName] forState:UIControlStateSelected];
       
        btn.frame = frame;
        
        self = btn;
    }
    
    
    return self;
}



#pragma mark
#pragma mark - 类主方法
+ (instancetype)z_buttonWithNormalImageName:(NSString *)normalImageName
                    andHighLightedImageName:(NSString *)highLightedName
                       andSelectedImageName:(NSString *)selectedName
                                   andImage:(NSString *)imageName
                       andImageSelectedName:(NSString *)imageSelected
                                   andTitle:(NSString *)title
                                   andFrame:(CGRect)frame{
    
    return [[self alloc]initWithNormalImageName:normalImageName andHighLightedImageName:highLightedName andSelectedImageName:selectedName andImage:imageName andImageSelectedName:imageSelected andTitle:title andFrame:frame];
}

#pragma mark
#pragma mark - 分方法(文字,backgroundImage三种状态,位置大小)
+ (instancetype)z_buttonWithNormalImageName:(NSString *)normalImageName andHighLightedImageName:(NSString *)highLightedName andSelectedImageName:(NSString *)selectedName  andTitle:(NSString *)title andFrame:(CGRect)frame{
 
    return [self z_buttonWithNormalImageName:normalImageName andHighLightedImageName:highLightedName andSelectedImageName: selectedName andImage:nil andImageSelectedName:nil andTitle:title andFrame:frame];
}

#pragma mark
#pragma mark - 分方法(文字,image三种状态,位置大小)
+ (instancetype)z_buttonWithImage:(NSString *)imageName andImageSelectedName:(NSString *)imageSelected andTitle:(NSString *)title andFrame:(CGRect)frame{
    
    return [self z_buttonWithNormalImageName:nil andHighLightedImageName:nil andSelectedImageName:nil andImage:imageName andImageSelectedName:imageSelected andTitle:title andFrame:frame];
}
@end
